/**
 * Copyright (c) 2008 Trent Hoeppner
 * 
 * This file is part of BillCalc.
 * 
 * BillCalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * BillCalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BillCalc.  If not, see <http://www.gnu.org/licenses/>.
 **/

package com.trentech.billcalc.event;

import java.util.Date;

import testcases.MainTest;

import com.trentech.billcalc.FinanceManager;


/**
 * BillSpecificEvent is a Bill for one person, and no others.  This is used for 
 * rent but can also be used for others.
 * 
 * @author Trent Hoeppner
 */
public class BillSpecificEvent extends BillEvent {

    /**
     * The name of the person who should pay.
     */
    private String owerName;
    
    
    /**
     * The name of the bill to pay.
     */
    private String billName;

    
    /**
     * Constructor for BillSpecificEvent.
     * 
     * @param   date        the date that the bill was issued.  Cannot be null.
     * @param   owedName    the name of the person who should be paid.  Cannot 
     *                      be null or empty.
     * @param   amount      the amount that the ower should pay the owed.  Must 
     *                      be >= 0.
     * @param   owerName    the name of the person who should pay.  Cannot be 
     *                      null or empty.
     * @param   billName    the name of the bill to use.  Cannot be null or 
     *                      empty.
     */
    public BillSpecificEvent(Date date, String owedName, int amount, 
            String owerName, String billName) {
        super(date, owedName, amount);

        this.owerName = owerName;
        this.billName = billName;
        
        setGenerated(true);
    }


    /**
     * {@inheritDoc}
     */
    public int compareTo(Event other) {
        int value = super.compareTo(other);
        if (value != 0) {
            return value;
        }
        
        BillSpecificEvent otherCasted = (BillSpecificEvent) other;
        value = owerName.compareTo(otherCasted.getOwerName());
        if (value != 0) {
            return value;
        }

        value = billName.compareTo(otherCasted.getBillName());
        if (value != 0) {
            return value;
        }
        
        // original : 
        // return 0;
        // seed fault :
        return (MainTest.isOriginal  ) ? 0 : 1;
    }
    
    
    /**
     * Charges the bill to a specific resident.
     * 
     * @param   manager the FinancialManager to help process this Event.  
     *                  Cannot be null.
     */
    public void process(FinanceManager manager) {
        manager.specificBillArrived(getName(), billName, getDate(), getAmount(), owerName);
    }


    /**
     * Returns the name of the person who should pay.
     * 
     * @return  the name of the person who should pay.  Will not be null or 
     *          empty.
     */
    public String getOwerName() {
        return owerName;
    }

    
    /**
     * Sets the name of the person who should pay.
     * 
     * @param   owerName    the name of the person who should pay.  Cannot be 
     *                      null or empty.
     */
    public void setOwerName(String owerName) {
        this.owerName = owerName;
    }


    /**
     * Returns the name of the bill to pay.
     * 
     * @return  the name of the bill to pay.  Will not be null or empty.
     */
    public String getBillName() {
        return billName;
    }


    /**
     * Sets the name of the bill to pay.
     * 
     * @param   billName    the name of the bill to pay.  Cannot be null or 
     *                      empty.
     */
    public void setBillName(String billName) {
        this.billName = billName;
    }
}
